import { Router } from 'express';
import { authenticate, authorize } from '../middlewares/auth';
import {
  getCourses,
  getCourseById,
  createCourse,
  updateCourse,
  deleteCourse,
  enrollCourse,
  getEnrolledCourses,
  updateLearningProgress,
} from '../controllers/course.controller';

const router = Router();

// 公开路由
router.get('/', getCourses);
router.get('/:id', getCourseById);

// 学生路由 - 需要认证
router.post('/:id/enroll', authenticate, enrollCourse);
router.get('/my/enrolled', authenticate, getEnrolledCourses);
router.post('/lessons/:lessonId/progress', authenticate, updateLearningProgress);

// 教师路由 - 需要认证和权限
router.post('/', authenticate, authorize('TEACHER', 'ADMIN'), createCourse);
router.put('/:id', authenticate, authorize('TEACHER', 'ADMIN'), updateCourse);
router.delete('/:id', authenticate, authorize('TEACHER', 'ADMIN'), deleteCourse);

export default router;
